package com.hanthink.web.controller.app.manhourfact;

import com.hanthink.common.constant.HttpStatus;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.page.TableDataInfo;
import com.hanthink.common.core.text.Convert;
import com.hanthink.framework.web.service.TokenService;
import com.hanthink.system.domain.manhour.FactWorkerUsed;
import com.hanthink.system.domain.manhour.ManHourFactPlanData;
import com.hanthink.system.domain.report.SecurityCollect;
import com.hanthink.system.service.manhour.IFactWorkerUsedService;
import com.hanthink.system.service.manhour.IManHourFactPlanDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author: lizhao
 * @codefunction:
 * @creatdate: 2022-02-17 3:06 PM
 */

@RestController
@RequestMapping("/app/manhourfact/report")
public class ManhourreportControll extends BaseController {
    @Autowired
    private IManHourFactPlanDataService manhourfactplandataService;

    @Autowired
    private IFactWorkerUsedService factWorkerUsedService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查詢临时用工明细,根据id
     */
    @PreAuthorize("@ss.hasPermi('differenceemployment')")
    @PostMapping("/plandatareport")
    public TableDataInfo queryplandatareport(@RequestBody Map<String, Object> map) throws ParseException {
        ManHourFactPlanData manhourfact =new ManHourFactPlanData();
        manhourfact.setCompanyid(map.get("companyid").toString());
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        manhourfact.setWorkdate(format.parse(map.get("workdate").toString()));
        List<ManHourFactPlanData> list = manhourfactplandataService.selectManHourFactPlanDataList(manhourfact);
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setCode(HttpStatus.SUCCESS);
        tableDataInfo.setMsg("操作成功");
        tableDataInfo.setRows(list);
        return tableDataInfo;
    }

    @PreAuthorize("@ss.hasPermi('filldetailsemployment')")
    @PostMapping("/filldetailsemployment")
    public TableDataInfo queryfilldetailsemploymentreport(@RequestBody Map<String, Object> map) throws ParseException {
        FactWorkerUsed factworkuserd =new FactWorkerUsed();
        factworkuserd.setCompanyid(map.get("companyid").toString());
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        factworkuserd.setPlanworkdatetime(format.parse(map.get("workdate").toString()));
        List<FactWorkerUsed> list = factWorkerUsedService.selectFactWorkerUsedReport(factworkuserd);
        for (int i = 0; i <list.size() ; i++) {
            switch (list.get(i).getWorkertype()){
                case "CZ":
                    list.get(i).setWorkertype("操作工");
                    break;
                case "L001":
                    list.get(i).setWorkertype("返工挑选");
                    break;
                case "L002":
                    list.get(i).setWorkertype("设备临时损坏或停机");
                    break;
                case "L003":
                    list.get(i).setWorkertype("临时性清洁工作");
                    break;
                case "L004":
                    list.get(i).setWorkertype("临时离厂");
                    break;
                case "L005":
                    list.get(i).setWorkertype("其他");
                    break;
                case "L006":
                    list.get(i).setWorkertype("试模打样");
                    break;
                case "L007":
                    list.get(i).setWorkertype("在线巡检");
                    break;
            }
        }
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setCode(HttpStatus.SUCCESS);
        tableDataInfo.setMsg("操作成功");
        tableDataInfo.setRows(list);
        return tableDataInfo;
    }
}
